
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="description" content="">
        <meta name="author" content="">

        <title>后台</title>

        <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

        <!-- Bootstrap core CSS -->
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/select2/select2.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/js/bootstrap-table/bootstrap-table.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
    </head>

    <body>

    <include file="Common/topNav" />

    <div class="container-fluid">
        <div class="row">
            <include file="Common/leftMenu" />
            <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                <div class="cont-title clearfix">
	        		<div class="title">街道列表</div>
	        	</div>
                <div class="table-responsive">

                    <table class="table table-striped table-hover" id="tableData">
                        <thead>
                            <tr>
                                <th>序号</th>
                                <th style="text-align: left;">机构名</th>
                                <th>简介</th>
                                <th>地址</th>
                                <th>管理员</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <volist name="orgList.rows" id="org">
                                <tr>
                                    <td>{$key+1}</td>
                                    <td style="text-align: left;">{$org.name}</td>
                                    <td title="{$org.introduce}">{$org.introduce|msubstr=###,0,30,"utf-8",true}</td>
                                    <td>{$org.address}</td>
                                    <td>
                                        <volist name="org['admins']" id="admin">
                                            <if condition="$key eq 0">
                                                {$admin.real_name}
                                                <else />
                                                ,{$admin.real_name}
                                            </if>
                                        </volist>
                                    </td>
                                    <td>
                                        <if condition="$sysUserRole['super'] eq 1">
                                            <a thisId="{$org['id']}" class="editOrg" href="javascript:void(0);">修改</a> |
                                        </if>
                                        <a thisId="{$org['id']}" class="setOrgAdmin" href="javascript:void(0);">管理员设置</a>
                                    </td>
                                </tr>
                            </volist>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    

    <include file="Common/modalHtmls" />
    
    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap-table/bootstrap-table.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap-table/bootstrap-table-locale-all.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/select2/select2.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
    <script>

        $(function () {
            $("#addOrg").click(function(){
                common.htmlAjax("{:U('Admin/Org/getOrgInfoById')}",{dataType:'html'},function(html){
                    $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
                });
            });

            $(".deleteOrg").click(function(){
                var orgId = $(this).attr("thisId");
                common.confirm("提示","确定删除组织机构?",function(){
                    common.ajax("{:U('Admin/Org/delOrg')}",{orgId:orgId},function(data){
                        //console.log(data);
                        common.alert("提示","组织机构删除成功!",function(){
                            common.reload();
                        });
                    })
                })
            });

            $(".editOrg").click(function(){
                var orgId = $(this).attr("thisId");
                common.htmlAjax("{:U('Admin/Org/getOrgInfoById')}",{orgId:orgId},function(html){
                    //console.log(html);
                    $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
                });
            });

            $(".setOrgAdmin").click(function(){
                var orgId = $(this).attr("thisId");
                common.htmlAjax("{:U('Admin/Org/setOrgAdmin')}",{orgId:orgId},function(html){
                    //console.log(html);
                    $("#commonModal").html(html).modal('toggle');
                });
            });
//            loadTableList();
//            $("#org_id").select2({
//                placeholder:'全部',
//                allowClear:true
//            });
//            $("#search_btn").bind("click",loadTableList);
        });

        function loadTableList() {
            var url = "{:U('Admin/Org/getOrgList')}";
            var columns = [
                //{checkbox: true,align: 'center'},
                {field: 'name',title: '机构名称',align: 'left',valign: 'middle'},
                {field: 'introduce',title: '简介',align: 'center',valign: 'middle'},
                {title: '地址',align: 'center',valign: 'middle',formatter:
                    function (value,row,index) {
                        var text = row.address;
                        if(row.pid == 0 && row.county) {
                            text = row.province.name+"-"+row.city.name+"-"+row.county.name+"-"+row.address;
                        }
                        return text;
                    }
                },
                {title: '管理员',align: 'center',valign: 'middle',formatter:
                    function (value,row,index) {
                        var text = '';
                        var admins = row.admins;
                        $.each(admins,function (index,item) {
                            if(index == 0) {
                                text = item.real_name;
                            } else {
                                text += ','+item.real_name;
                            }
                        });
                        return text;
                    }
                },
                {title: "操作",align: 'center',valign: 'middle',formatter:
                    function (value, row, index) {
                        var btn = '<a thisId="'+row.id+'" class="editOrg" href="javascript:void(0);">修改</a> | ';
                        btn += '<a thisId="'+row.id+'" class="setOrgAdmin" href="javascript:void(0);">管理员设置</a>';
                        return btn;
                    }
                }
            ];
            var options = {};
            var param = {
                pid: $("#org_id").val()
            };

            common.loadTableData("tableData",url,columns,param,options,function () {
                $(".pagination-detail").remove();
                $(".deleteOrg").click(function(){
                    var orgId = $(this).attr("thisId");
                    common.confirm("提示","确定删除组织机构?",function(){
                        common.ajax("{:U('Admin/Org/delOrg')}",{orgId:orgId},function(data){
                            //console.log(data);
                            common.alert("提示","组织机构删除成功!",function(){
                                common.reload();
                            });
                        })
                    })
                });

                $(".editOrg").click(function(){
                    var orgId = $(this).attr("thisId");
                    common.htmlAjax("{:U('Admin/Org/getOrgInfoById')}",{orgId:orgId},function(html){
                        //console.log(html);
                        $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
                    });
                });

                $(".setOrgAdmin").click(function(){
                    var orgId = $(this).attr("thisId");
                    common.htmlAjax("{:U('Admin/Org/setOrgAdmin')}",{orgId:orgId},function(html){
                        //console.log(html);
                        $("#commonModal").html(html).modal('toggle');
                    });
                });
            });
        }

    </script>
</body>
</html>
